package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入要借阅的书名");
        String name=scan.nextLine();
        int size=bookList.getSize();
        for(int i=0;i<size;i++){
            Book book=bookList.getBooks(i);
            if(book.getName().equals(name)){
                if(!book.getState()) {
                    book.setState(true);
                    System.out.println("借阅成功");
                    return ;
                }else{
                    System.out.println("此书已借出");
                    return ;
                }
            }
        }
        System.out.println("没有此书");
    }
}
